package dog;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Dog {


    public static void main(String[] args) {



            String content="https://91caiqing.com/index/person";
            String pattern=".*runoob.*";
            String regex ="https://.*?";
            boolean isMatch=Pattern.matches(regex, content);
            System.out.println("字符串中是否包含了‘runoob’子字符串？"+isMatch);
            //System.out.println("startUrl:"+myurl.startUrl);
            //System.out.println("urlcontent:"+myurl.urlContent);
            //System.out.println("ContentArea:"+myurl.ContentArea);

//        System.setProperty("webdriver.chrome.driver","/usr/local/bin/chromedriver");
//
//        //初始化一个chrome浏览器实例driver
//        WebDriver driver = new ChromeDriver();
//        // get(url)打开一个网站
//        driver.get("https://www.taobao.com");
//
//
//        //getTitle()获取当前页面标题
//        System.out.println("当前打开页面的标题是： "+ driver.getTitle());
//        //关闭并退出浏览器
//        driver.quit();

        aaa();
    }

    public static void aaa() {
        //默认是贪婪匹配,暂时还没尝试写一个正则匹配
        String urlRegex = "https?://(\\w|-)+(\\.(\\w|-)+)+(/(\\w|-)+(/((\\w|-)+\\.(\\w|-)+)|/(\\w|-)*)|(/((\\w|-)+\\.(\\w|-)+)|/(\\w|-)+)|/?)/(((\\w|-)+\\.(\\w|-)+)|(\\w|-)+(\\?\\w+=(\\w|-|%|[\u4e00-\u9fa5])+(\\&\\w+=(\\w|-|%|[\u4e00-\u9fa5])+)*)?)";

        urlRegex = "https?://(\\w|-)+(\\.(\\w|-)+)+(/(\\w|-)+(/((\\w|-)+\\.(\\w|-)+)|/(\\w|-)*)|(/((\\w|-)+\\.(\\w|-)+)|/(\\w|-)+)|/?)/(((\\w|-)+\\.(\\w|-)+)|(\\w|-)*(\\?\\w+=(\\w|-|%|[\u4e00-\u9fa5])+(\\&\\w+=(\\w|-|%|[\u4e00-\u9fa5])+)*)?)";
        urlRegex = "https?://(\\w|-)+(\\.(\\w|-)+)+(/(\\w+(\\?(\\w+=(\\w|%|-)*(\\&\\w+=(\\w|%|-)*)*)?)?)?)+";//修改版
        String urlRegex2 = "https?://(\\w|-)+(\\.(\\w|-)+)+(/(\\w|-)+(/((\\w|-)+\\.(\\w|-)+)|/(\\w|-)*)|(/((\\w|-)+\\.(\\w|-)+)|/(\\w|-)+)|/?)";
        //我在百度搜索了java 正则表达式,然后复制了放在url里面的
        String url = "https://www.baidu.com/s?wd=java%20%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F&rsv_spt=1&rsv_iqid=0xf233885e000326c0&issp=1&f=8&rsv_bp=0&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=24&rsv_sug1=8&rsv_sug7=100&rsv_t=0d31XJ5IR0T98Bv150wUMKQHirYYsh2IgKsJFk0FH4wGur10ND3LypRnWtdrcFCsDH%2F3&rsv_sug2=0&inputT=6942&rsv_sug4=6942";
        //这个就是不带参数的url了
        String url2 = "https://www.baidu.com";
        Pattern pattern = Pattern.compile(urlRegex);
        Matcher matcher = pattern.matcher(url);
        String isSuccess = "不匹配";
        if(matcher.matches()){
            isSuccess = "匹配";
        }
        System.out.println(isSuccess);
        pattern = Pattern.compile(urlRegex2);
        matcher = pattern.matcher(url2);
        isSuccess = "不匹配";
        if(matcher.matches()){
            isSuccess = "匹配";
        }
        System.out.println(isSuccess);
    }

}
